package com.ericsson.rm.util;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.MessageFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * This class contains commonly used utility methods.
 * All methos in this class is public & static and exposed to everybody.
 * 
 * @author Suman(Ericsson)
 */
public class Utility {

	public Utility() {
		super();
	}
	
	/**
	 * This method checks whether the source String is empty.
	 * @param source String
	 * @return true if source is empty, false if source is not empty.
	 * @author Suman(Ericsson)
	 */
	public static boolean isEmpty(String source){
		
		return (null == source || source.trim().equals("")) ? true : false ;
	}
	
	/**
	 * This method checks whether the source Collection is empty.
	 * @param source Collection
	 * @return true if source Collection is empty, false if source Collection is not empty.
	 * @author Suman(Ericsson)
	 */
	public static boolean isEmpty(Collection source){
		
		return (null == source || source.isEmpty()) ? true : false ;
	}
	
	/**
	 * This method checks whether the source Object is empty.
	 * @param source Object
	 * @return true if source is empty, false if source is not empty.
	 * @author Suman(Ericsson)
	 */
	public static boolean isEmpty(Object source){
		
		return (null == source) ? true : false ;
	}
	
	/**
	 * This method checks whether the source array is empty.
	 * @param source Object[]
	 * @return true if source array is empty, false if source array is not empty.
	 * @author Suman(Ericsson)
	 */
	public static boolean isEmpty(Object[] source){
		
		return (null == source || source.length <= 0) ? true : false ;
	}
		
	/**
	 * This method checks whether the source String is not empty.
	 * @param source String
	 * @return true if source is not empty, false if source is empty.
	 * @author Suman(Ericsson)
	 */
	public static boolean isNotEmpty(String source){
		
		return !isEmpty(source);
	}
	
	/**
	 * This method checks whether the source Collection is not empty.
	 * @param source Collection
	 * @return true if source Collection is not empty, false if source Collection is empty.
	 * @author Suman(Ericsson)
	 */
	public static boolean isNotEmpty(Collection source){
		
		return !isEmpty(source);
	}
	
	/**
	 * This method checks whether the source Object is not empty.
	 * @param source Object
	 * @return true if source is not empty, false if source is empty.
	 * @author Suman(Ericsson)
	 */
	public static boolean isNotEmpty(Object source){
		
		return !isEmpty(source);
	}
	
	/**
	 * This method checks whether the source Object[] is not empty.
	 * @param source Object[]
	 * @return true if source array is not empty, false if source array is empty.
	 * @author Suman(Ericsson)
	 */
	public static boolean isNotEmpty(Object[] source){
		
		return !isEmpty(source);
	}
	
	/**
	 * This method will copy source Bean's state i.e all properties to target Bean.
	 * This method should be invoked passing concrete source Bean object and 
	 * java.lang.Class instance of the target bean class.
	 * This method should be invoked when target bean object is not available.
	 * Both beans should have 
	 * 		i)Same number of properties with same name and same data type
	 * 		ii)Corresponding standard getXXX() and setXXX() methods
	 * @param source Bean object
	 * @param targetClass i.e. java.lang.Class instance of the target bean class. 
	 * @return target Bean object after copying all properties from source bean.
	 * @throws IllegalArgumentException if source Bean is null.
	 * @author Suman(Ericsson)
	 */
	public static Object copyBean(Object source, Class targetClass) throws IllegalArgumentException {
		
		if(null == source){
			throw new IllegalArgumentException("Source Bean is null");
		}
		Object targetObj = null;
		try {
			targetObj = targetClass.newInstance();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InstantiationException e) {
			e.printStackTrace();
		}
		
		return copyBean(source, targetObj);
	}
	
	/**
	 * This method will copy source Bean's state i.e all properties to target Bean. <br>
	 * This method should be invoked passing two concrete Bean object. <br/>
	 * Both beans should have <br/>
	 * 	<li>i)Same number of properties with same name and same data type. </li>
	 * 	<li>ii)Corresponding standard getXXX() and setXXX() methods. </li>
	 * 
	 * @param source Bean object
	 * @param target Bean object
	 * @return target Bean object after copying all properties from source bean.
	 * @throws IllegalArgumentException 
	 * 		   <li>(i)If either source or target Bean is null. </li>
	 * 		   <li>(ii)If number of properties are different in two Beans. </li>
	 * @author Suman(Ericsson)
	 */
	public static Object copyBean(Object source, Object target) throws IllegalArgumentException {
		
		if(null == source || null == target){
			throw new IllegalArgumentException("Either source or target Bean is null"+"\n Source Bean ->"+source+" Target Bean ->"+target);
		}
		
		BeanInfo sourceBeanInfo=null;
		BeanInfo targetBeanInfo=null;
		try {
			sourceBeanInfo = Introspector.getBeanInfo(source.getClass());
			targetBeanInfo = Introspector.getBeanInfo(target.getClass());
		} catch (IntrospectionException e) {
			e.printStackTrace();
		}
		
		PropertyDescriptor[] sourcePropDescArr = sourceBeanInfo.getPropertyDescriptors();
		PropertyDescriptor[] targetPropDescArr = targetBeanInfo.getPropertyDescriptors();
		
		if(sourcePropDescArr.length != targetPropDescArr.length){
			throw new IllegalArgumentException("Number of properties are different in two Beans..." +
					"\n Number of properties in source Bean ->"+sourcePropDescArr.length+
					"\n Number of properties in target Bean ->"+targetPropDescArr.length);
		}
		
		Method sourceBeanMethod = null;
		Method targetBeanMethod = null;
		
		for(int i=0; i<sourcePropDescArr.length; i++){
			sourceBeanMethod = sourcePropDescArr[i].getReadMethod();
			targetBeanMethod = targetPropDescArr[i].getWriteMethod();
			//System.out.println("sourcePropDescArr[i].getReadMethod() :"+sourceBeanMethod);
			//System.out.println("targetPropDescArr[i].getWriteMethod() :"+targetBeanMethod);
			
			if(targetBeanMethod != null && sourceBeanMethod != null){
				try {
					targetBeanMethod.invoke(target, sourceBeanMethod.invoke(source));
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				} catch (InvocationTargetException e) {
					e.printStackTrace();
				}
			}
		}

		return target;
	}
	
	
	/**
	 * This method will copy source Bean's state i.e all properties to target Bean even if both the beans are dissimilar.<br/>
	 * Whatever matching bean properties will be found between source & target bean, will be copied. <br/>
	 * Other unmatching bean properties will remain unchanged. <br/>
	 * This method should be invoked passing two concrete Bean object. 
	 * 
	 * @param source Bean object
	 * @param target Bean object
	 * @return target Bean object after copying all properties from source bean.
	 * @throws IllegalArgumentException if either source or target Bean is null.
	 * @author Suman(Ericsson)
	 */
	public static Object copyDissimilarBean(Object source, Object target) throws IllegalArgumentException {
		
		if(null == source || null == target){
			throw new IllegalArgumentException("Either source or target Bean is null"+"\n Source Bean ->"+source+" Target Bean ->"+target);
		}
		
		BeanInfo sourceBeanInfo=null;
		BeanInfo targetBeanInfo=null;
		Method sourceBeanGetMethod = null;
		Method targetBeanGetMethod = null;
		Method targetBeanSetMethod = null;
		
		try {
			sourceBeanInfo = Introspector.getBeanInfo(source.getClass());
			targetBeanInfo = Introspector.getBeanInfo(target.getClass());
		} catch (IntrospectionException e) {
			e.printStackTrace();
		}
		
		PropertyDescriptor[] sourcePropDescArr = sourceBeanInfo.getPropertyDescriptors();
		PropertyDescriptor[] targetPropDescArr = targetBeanInfo.getPropertyDescriptors();
		
		//System.out.println("sourcePropDescArr.length : "+sourcePropDescArr.length);
		//System.out.println("targetPropDescArr.length : "+targetPropDescArr.length);
		
		for(int i=0; i<targetPropDescArr.length; i++){
			targetBeanSetMethod = targetPropDescArr[i].getWriteMethod();
			targetBeanGetMethod = targetPropDescArr[i].getReadMethod();
			String targetGetMethodName = targetBeanGetMethod.getName();
			
			//System.out.println("targetPropDescArr["+i+"].getReadMethod() :"+targetBeanGetMethod);
			//System.out.println("targetPropDescArr["+i+"].getWriteMethod() :"+targetBeanSetMethod);
			//System.out.println("targetGetMethodName["+i+"] :"+targetGetMethodName);
			
			if(targetBeanSetMethod != null) {
				for(int j=0; j<sourcePropDescArr.length; j++){
					sourceBeanGetMethod = sourcePropDescArr[j].getReadMethod();
					//System.out.println("sourcePropDescArr["+j+"].getReadMethod() :"+sourceBeanGetMethod);	
					
					if(sourceBeanGetMethod != null){
						String sourceGetMethodName = sourceBeanGetMethod.getName();
						//System.out.println("sourceGetMethodName["+j+"] :"+sourceGetMethodName);
						
						if(targetGetMethodName.equals(sourceGetMethodName)){
							try {
								targetBeanSetMethod.invoke(target, sourceBeanGetMethod.invoke(source));
								break;
							} catch (IllegalAccessException e) {
								e.printStackTrace();
							} catch (InvocationTargetException e) {
								e.printStackTrace();
							}
						}
					}
				}
			}
		}
		
		return target;
	}
	
	/**
	 * This method will display the content of the passed java bean. <br/>
	 * It will return a String which contains name and value of all properties of that bean.
	 * 
	 * @param bean object to be displayed
	 * @return String 
	 * @author Suman(Ericsson)
	 */
	public static String displayBean(Object bean) {
		StringBuffer buf = new StringBuffer(256);
		if(null == bean){
			return "Input Bean object is null";
		}
		
		Class beanClass = bean.getClass();
		String beanName = beanClass.getSimpleName();
		BeanInfo sourceBeanInfo=null;

		try {
			sourceBeanInfo = Introspector.getBeanInfo(beanClass);
		} catch (IntrospectionException e) {
			e.printStackTrace();
		}
		
		PropertyDescriptor[] beanPropDescArr = sourceBeanInfo.getPropertyDescriptors();
		Method getterMethod = null;
		Method setterMethod = null;
		String beanPropertyName = null;

		buf.append("[ "+beanName+": ");
		for(int i=0; i<beanPropDescArr.length; i++) {
			getterMethod = beanPropDescArr[i].getReadMethod();
			setterMethod = beanPropDescArr[i].getWriteMethod();
			beanPropertyName = beanPropDescArr[i].getName();
			//System.out.println("sourcePropDescArr[i].getReadMethod() :"+getterMethod);
			//System.out.println("targetPropDescArr[i].getWriteMethod() :"+setterMethod);
			//System.out.println("sourcePropDescArr["+i+"].getName() :"+beanPropertyName);
			
			if(beanPropertyName !=null && getterMethod != null && setterMethod !=null ){
				try {
					buf.append(beanPropertyName+"=");
					
					Object beanPropertyValue = null;
					try {
						beanPropertyValue = getterMethod.invoke(bean);
					} catch (InvocationTargetException e) {
						//Don't display the bean property if InvocationTargetException occures.
						e.printStackTrace();
					}
					
					if(beanPropertyValue != null){
						
						if (beanPropertyValue.getClass().isPrimitive()){
							buf.append(beanPropertyValue);
						} else if(isDate(beanPropertyValue)) {
							buf.append(convertDateToString((Date)beanPropertyValue));
						} else if(isBean(beanPropertyValue)){
							buf.append(displayBean(beanPropertyValue));
						} else if(isArray(beanPropertyValue)){
							buf.append("[");
							for(int j=0; j<Array.getLength(beanPropertyValue); j++){
								Object arrayElement = Array.get(beanPropertyValue, j);
								if(isBean(arrayElement)){
									buf.append(displayBean(arrayElement));
								} else {
									buf.append(arrayElement);
								}
								buf.append(", ");
							}
							buf.append("] ");
						} else {
							buf.append(beanPropertyValue);
						}
							
					} else {
						buf.append(beanPropertyValue);
					}
				} catch (IllegalAccessException e) {
					throw new RuntimeException(e);
				}
			}
			buf.append(" ");
		}
		
		buf.append("]\n");
		return buf.toString();
	}
	
	/**
	 * This method will display the content of the passed array of Objects. <br/>
	 * It will return a String which contains name and value of all properties of each object of the array.
	 * 
	 * @param objArray i.e array of Object to be displayed
	 * @return String 
	 * @author Suman(Ericsson)
	 */
	public static String displayArrayBean(Object[] objArray) {
		StringBuffer buf = new StringBuffer(256);
		
		if(isNotEmpty(objArray)){
			buf.append("{");
			for(Object arrayElement : objArray){
				if(isBean(arrayElement)){
					buf.append(displayBean(arrayElement));
				} else {
					buf.append(arrayElement);
				}
				buf.append(", ");
			}
			buf.append("} ");
		} else {
			return "Input array object provided is null or empty";
		}
		
		return buf.toString();
	}
	
	/**
	 * This method will display the content of the passed collection of Objects. <br/>
	 * It will return a String which contains name and value of all properties of each object of the collection.
	 * 
	 * @param collection i.e Collection of Object to be displayed
	 * @return String 
	 * @author Suman(Ericsson)
	 */
	public static String displayCollectionBean(Collection collection) {
		StringBuffer buf = new StringBuffer(256);
		
		if(isNotEmpty(collection)){
			buf.append("{");
			Iterator itr = collection.iterator();
			Object element = null;
			
			while(itr.hasNext()){
				element = itr.next();
				if(isNotEmpty(element)){
					if(isBean(element)){
						buf.append(displayBean(element));
					} else if(isCollection(element)) {
						buf.append(displayCollectionBean((Collection)element));
					} else {
						buf.append(element);
					}
					buf.append(", ");
				}
			}
			buf.append("} ");
		} else {
			return "Input Collection object provided is null or empty";
		}
		
		return buf.toString();
	}
	
	/**
	 * This will check whether the passed object is a Java Bean or not.
	 * @param bean Object
	 * @return isBean - boolean
	 * @author Suman(Ericsson)
	 */
	private static boolean isBean(Object bean) {
		boolean isBean = false;
		BeanInfo sourceBeanInfo = null;

		try {
			sourceBeanInfo = Introspector.getBeanInfo(bean.getClass());
		} catch (IntrospectionException e) {
			e.printStackTrace();
		}
		
		PropertyDescriptor[] beanPropDescArr = sourceBeanInfo.getPropertyDescriptors();
		Method getterMethod = null;
		Method setterMethod = null;
		String beanPropertyName = null;

		for(int i=0; i<beanPropDescArr.length; i++) {
			getterMethod = beanPropDescArr[i].getReadMethod();
			setterMethod = beanPropDescArr[i].getWriteMethod();
			beanPropertyName = beanPropDescArr[i].getName();
//			System.out.println("beanPropertyName["+i+"] -> "+beanPropertyName);
//			System.out.println("setterMethod["+i+"] -> "+setterMethod);
//			System.out.println("getterMethod["+i+"] -> "+getterMethod);
			
			if(beanPropertyName != "class") {
				if(getterMethod == null || setterMethod == null ){
					isBean = false;
				} else {
					isBean = true;
					break;
				}	
			}
		}
		
		return isBean;
	}
	
	/**
	 * This method converts a Date to String with format - "dd/MM/yyyy"
	 * @param date Date
	 * @return String - dateStr
	 * @author Suman(Ericsson)
	 */
	public static String convertDateToString(Date date) {    	
    	return convertDateToString(date, "dd/MM/yyyy");
    }
	
	/**
	 * This method converts a Date to String with provided format.
	 * @param date Date
	 * @param format String
	 * @return String - dateStr
	 * @author Suman(Ericsson)
	 */
	public static String convertDateToString(Date date, String format) {
				
		SimpleDateFormat formatter = new SimpleDateFormat(format);
    	String dateStr = formatter.format(date);
    	
    	return dateStr;
    }
	
	/**
	 * This method converts a Date to String with format - "dd-MMM-yyyy HH:mm:ss"
	 * @param date Date
	 * @return String - dateStr
	 * @author Suman(Ericsson)
	 */
	public static String convertDateToFormattedDateTimeString(Date date) {
				
		SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
    	String dateStr = formatter.format(date);    	
    	return dateStr;
    }
	
	/**
	 * This method replaces the last occurrence of a String in a String
	 * @param expr String
	 * @param textFind String
	 * @param substitute String
	 * @return String
	 * @author Suman(Ericsson)
	 */
	public String replaceLast(String expr, String textFind, String substitute) {
		if(expr.lastIndexOf(textFind)==-1){
			return expr;
		}
		
		return expr.substring(0,expr.lastIndexOf(textFind))+substitute+expr.substring(expr.lastIndexOf(textFind)+textFind.length());		
    }
	
	/**
	 * This method converts a String to a Date with format - "dd/MM/yyyy"
	 * @param date String : the date value to be converted
	 * @return convertedDate - Date
	 * @author Suman(Ericsson)
	 */
	public static Date convertStringToDate(String date){	
	    return convertStringToDate(date,"dd/MM/yyyy");	
	}
	
	/**
	 * This method converts a String to a Date with specified format
	 * @param date String : the date value to be converted
	 * @param format String
	 * @return convertedDate - Date
	 * @author Suman(Ericsson)
	 */
	public static Date convertStringToDate(String date, String format){
		Date convertedDate = null;
		SimpleDateFormat dateFormat = new SimpleDateFormat(format); 
	    
	    try {
			convertedDate = dateFormat.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
	    return convertedDate;	
	}
	
	/**
	 * This method will return a Properties object for given properties file.
	 * @param configPropertiesFilepath String
	 * @return serviceConfigProperties - Properties
	 * @author Suman(Ericsson)
	 */
	public static Properties getConfigurationFromClassPath(String configPropertiesFilepath){
		Properties serviceConfigProperties = null;
		serviceConfigProperties = getProperties(configPropertiesFilepath);
		return serviceConfigProperties;
	}
	
	private static Properties getProperties(String resourceBundlePath){
		Properties prop = new Properties();  
		try {
			InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceBundlePath);
			prop.load(is);
		} catch (IOException e) {
			System.out.println("Unable to locate resource bundle");
			e.printStackTrace();
		}
	   
		return prop;
	}
	
	/**
	 * This will convert the stackTrackInto String object.
	 * @param t Throwable
	 * @return stackTraceMessage - String
	 * @author Suman(Ericsson)
	 */
	public static String getStackTrace(Throwable t) {
		String stackTraceMessage = null;
		
	    final Writer writer = new StringWriter();
	    final PrintWriter printWriter = new PrintWriter(writer, Boolean.TRUE);
	    t.printStackTrace(printWriter);
	    stackTraceMessage = writer.toString();
	    
	    return stackTraceMessage;
	}
	
	/**
	 * This will check whether the source object is an Array or not.
	 * @param source Object
	 * @return isArray - boolean
	 * @author Suman(Ericsson)
	 */
	private static boolean isArray(Object source){
		boolean isArray = false;
		isArray = source.getClass().isArray();
		return isArray;
	}
	
	/**
	 * This will check whether the source object is an Collection or not.
	 * @param source Object
	 * @return isCollection - boolean
	 * @author Suman(Ericsson)
	 */
	private static boolean isCollection(Object source){
		boolean isCollection = false;
		isCollection = (source instanceof Collection) ? Boolean.TRUE : Boolean.FALSE;
		return isCollection;
	}
	
	/**
	 * This will check whether the source object is an Array or not.
	 * @param source Object
	 * @return isDate - boolean
	 * @author Suman(Ericsson)
	 */
	private static boolean isDate(Object source){
		boolean isDate = false;
		isDate =  (source instanceof java.util.Date || source instanceof java.sql.Date || source instanceof java.sql.Timestamp) ? Boolean.TRUE : Boolean.FALSE;
		return isDate;
	}
	
	/**
	 * This method checks whether the source String is null, if so, returns empty string.
	 * @param source String
	 * @return String
	 * @author Suman(Ericsson)
	 */
	public static String formatNullString(String source){
		
		return (null == source) ? "" : source ;
	}
	
	/**
	 * This method checks whether the source number is null, if so, returns zero.
	 * @param number Long
	 * @return Long
	 * @author Suman(Ericsson)
	 */
	public static Long formatNullLong(Long number){
		
		return Utility.isEmpty(number) ? 0L : number;
	}
	
	/**
	 * This method can be used as an alternative to replaceAll method <BR/>
	 * which take care of special character ($) in the replacing string
	 * 
	 * @param strOrig String
	 * @param strFind String
	 * @param strReplace String
	 * @return String
	 * @author Suman(Ericsson)
	 */
	public static String replaceAllString(String strOrig, String strFind, String strReplace) {
		if(strOrig == null) {
			return "";
		}
		
		StringBuffer sb = new StringBuffer(strOrig);
		
		String toReplace = "";
		if (strReplace == null) {
			toReplace = "";
		}	
		else {
			toReplace = strReplace;
		}	
		
		int pos = strOrig.length();
		
		while (pos > -1) {
			pos = strOrig.lastIndexOf(strFind, pos);
			if (pos > -1) sb.replace(pos, pos+strFind.length(), toReplace);
			pos = pos - strFind.length();
		}
		
		return sb.toString();
	}
	
	/**
	 * This method converts an Object array to a Set.
	 * @param array Object[]
	 * @return set - Set
	 * @author Suman(Ericsson)
	 */
	public static Set convertArrayToSet(Object[] array){
		Set set = null;
		if(isNotEmpty(array)){
			set = new HashSet();
			
			for(Object obj : array){
				set.add(obj);
			}
		}
		
		return set;
	}
	
	public static Boolean isOdd(int number){
		Boolean isOdd = Boolean.FALSE;
		
		if(number != 0 && number%2 != 0){
			isOdd = Boolean.TRUE;
		}
		
		return isOdd;
	}
	
	/**
	 * This method calculates the sum of all numbers present inside input int[].
	 * @param numbers int[]
	 * @return sum - Sum of all numbers present inside int[]
	 * @author Suman(Ericsson)
	 */
	public static int calculateSum(int[] numbers){
		int sum = 0;
		for(int number : numbers){
			sum = sum + number;
		}
		
		return sum;
	}

	public static String formatYearRange(String yearRange) {
		String formattedYearRange = null;
		String min = null;
		String max = null;
		
		if(isNotEmpty(yearRange)){
			int index = yearRange.indexOf('-');
			if(index > 0){
				min = yearRange.substring(0, index);
				max = yearRange.substring(index+1);
			} else {
				int plusIndex = yearRange.indexOf('+');
				if(plusIndex>0){
					min = yearRange.substring(0, plusIndex);
					max = Integer.toString(Integer.parseInt(min)*10);
				}
			}
			formattedYearRange = min + " AND " + max;
		}
		
		System.out.println("FormattedYearRange -> "+formattedYearRange);
		return formattedYearRange;
	}
	
	public static String getMinValueOfYearRange(String yearRange) {
		String minValue = null;
		
		if(isNotEmpty(yearRange)){
			int index = yearRange.indexOf('-');
			if(index > 0){
				minValue = yearRange.substring(0, index);
			} else {
				int plusIndex = yearRange.indexOf('+');
				if(plusIndex>0){
					minValue = yearRange.substring(0, plusIndex);
				}
			}
		}
		
		return minValue;
	}
	
	public static String getMaxValueOfYearRange(String yearRange) {
		String maxValue = null;
		
		if(isNotEmpty(yearRange)){
			int index = yearRange.indexOf('-');
			if(index > 0){
				maxValue = yearRange.substring(index+1);
			} else {
				int plusIndex = yearRange.indexOf('+');
				if(plusIndex>0){
					maxValue = Integer.toString(Integer.parseInt(yearRange.substring(0, plusIndex))*10);
				}
			}
		}
		
		return maxValue;
	}
	
	/**
	 * It fetches day of the date having specific format MM/DD/YYYY.
	 * @param releaseDate
	 * @return map containing day and month of the date.
	 */
	public static Map<String, String> getDayAndMonthOfDate(String date) {
		Map<String, String> dayMonthMap = new HashMap<String, String>();
		
		//date = date.substring(0,date.lastIndexOf("/"));
		
		String month = date.substring(0, date.indexOf("/"));
		dayMonthMap.put("MONTH", month);
		
		String day = date.substring(date.indexOf("/")+1, date.lastIndexOf("/"));
		dayMonthMap.put("DAY", day);
		
		return dayMonthMap;
	}
	
	public static String getFormattedMessage(String message, Object[] args) {
		String formattedMessage = MessageFormat.format(message, args);
		
		return formattedMessage;
	}
	
	public static String createInQueryArgumrnts(List<String> arguments) {
		
		final String COMMA = ",";
		final String SPACE = " ";
		final String QOUTE = "'";
		final String LEFT_BRACKET = "(";
		final String RIGHT_BRACKET = ")";
		
		String queryArgs = null;
		
		if(isNotEmpty(arguments)){
			StringBuilder sBld = new StringBuilder();
			sBld.append(LEFT_BRACKET);
			
			for(int i=0; i<arguments.size(); i++){
				sBld.append(QOUTE);
				sBld.append(arguments.get(i));
				sBld.append(QOUTE);
				sBld.append(COMMA);
				sBld.append(SPACE);
			}
			queryArgs = sBld.substring(0, sBld.lastIndexOf(COMMA));
			queryArgs = queryArgs + RIGHT_BRACKET;
		}
		
		return queryArgs;
	}
}
